{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "连接成功\n",
      "<xtquant.xttype.StockAccount object at 0x0000028CA6C9FE50>\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "from xtquant.xttrader import XtQuantTrader\n",
    "\n",
    "# miniQMT安装路径\n",
    "mini_qmt_path = r'D:\\国金证券QMT交易端\\userdata_mini'\n",
    "# 创建session_id\n",
    "session_id = int(random.randint(100000, 999999))\n",
    "# 创建交易对象\n",
    "xt_trader = XtQuantTrader(mini_qmt_path, session_id)\n",
    "# 启动交易对象\n",
    "xt_trader.start()\n",
    "# 连接客户端\n",
    "connect_result = xt_trader.connect()\n",
    "\n",
    "if connect_result == 0:\n",
    "    print('连接成功')\n",
    "\n",
    "from xtquant.xttype import StockAccount\n",
    "# QMT账号\n",
    "account_id = '1010573943'\n",
    "# 创建账号对象\n",
    "account = StockAccount(account_id)\n",
    "# 订阅账号\n",
    "res = xt_trader.subscribe(account)\n",
    "print(account)\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[<xtquant.xtpythonclient.XtOrder object at 0x0000028CA6C2F770>]\n",
      "账号类型： 2\n",
      "资金账号： 1010573943\n",
      "证券代码： 600000.SH\n",
      "订单编号： 1082425084\n",
      "柜台合同编号： 688\n",
      "报单时间： 1712677905\n",
      "委托类型： 23\n",
      "委托数量： 100\n",
      "报价类型： 50\n",
      "委托价格： 7.26\n",
      "成交数量： 0\n",
      "成交均价： 0.0\n",
      "委托状态： \n",
      "委托状态描述： 54\n"
     ]
    }
   ],
   "source": [
    "orders = xt_trader.query_stock_orders(account, cancelable_only = False)\n",
    "print(orders)\n",
    "for order in orders:\n",
    "  print('账号类型：', order.account_type)\n",
    "  print('资金账号：', order.account_id)\n",
    "  print('证券代码：', order.stock_code)\n",
    "  print('订单编号：', order.order_id)\n",
    "  print('柜台合同编号：', order.order_sysid)\n",
    "  print('报单时间：', order.order_time)\n",
    "  print('委托类型：', order.order_type)\n",
    "  print('委托数量：', order.order_volume)\n",
    "  print('报价类型：', order.price_type)\n",
    "  print('委托价格：', order.price)\n",
    "  print('成交数量：', order.traded_volume)\n",
    "  print('成交均价：', order.traded_price)\n",
    "  print('委托状态：', order.status_msg)\n",
    "  print('委托状态描述：', order.order_status)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "miniqmt-demo-cptEsqYo-py3.10",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
